class Admin::BookReserveController < ApplicationController
  # specific layout
  layout 'admin/application'
  
  def index
    @reserved_books = BookReserve.order('created_at desc').paginate(:page => params[:page], :per_page => 10)
  end
  
  def check
    @reserved_book = BookReserve.find(params[:id])
    if params[:send_email]
      user_id = @reserved_book.user.id
      user = User.find(user_id)
      UserMailer.remind_reader_to_borrow_book(user, @reserved_book).deliver
      @reserved_book.update_attributes(:is_checked => 1)
      flash[:notice] = "An email have been sent to reader to notice about the availability of book"
    end
  end
  
  def delete
    reserved_book = BookReserve.find(params[:id])
    reserved_book.destroy
    
    redirect_to :controller => "admin/book_reserve", :action => "index"
  end
end
